#include<string>
#include<queue>
#include<set>
#include<vector>
#include<memory>
#include"TcpConnection.h"
using std::string;
using std::priority_queue;
using std::set;
using std::vector;
using std::shared_ptr;
using TcpConnectionPtr=shared_ptr<TcpConnection>;
class TcpConnection;
class MyResult{
    public:
    MyResult(int,int,string);
    bool operator<(const MyResult&rhs)const;
    string getWord()const;
    void print()const;
    private:
    int _distance;
    int _count;
    string _word;

};
class KeyRecommander{
    public:
    KeyRecommander(string ,TcpConnectionPtr);
    //执行查询
    void execute();
    //遍历关键词拿到候选词索引set，根据set取候选词
    void queryIndexTable();
    //计算编辑距离
    int distance(const string rhs);
    //回复响应
    void response();


    set<int> unionOfSets(const std::set<int>& set1, const std::set<int>& set2);
    set<int> getUnionSet(vector<set<int>> &sets);
    size_t nByetesCode(const char ch);
    
    private:
    string _queryWord;
    priority_queue<MyResult> priMyResult;
    TcpConnectionPtr _conn;
};

